/* 
 * File:   Coordinate.cpp
 * Author: Lucky
 * 
 * Created on 22. září 2011, 9:23
 */

#include "Coordinate.h"
#include "LightException.h"

Coordinate::Coordinate(int x, int y) {
    if (x < 0 || y < 0) {
        throw new LightException("Bad Coordinates!");
    }
    this->m_x = x;
    this->m_y = y;
}

Coordinate::Coordinate(const Coordinate& orig) {
    this->m_x = orig.m_x;
    this->m_y = orig.m_y;
}

Coordinate::~Coordinate() {
}

int Coordinate::getX() const {
    return this->m_x;
}

int Coordinate::getY() const {
    return this->m_y;
}

int Coordinate::getLength(int width) const {
    return m_y * width + m_x;
}

Coordinate Coordinate::getNextCoordinate(int width) const {
    int x = m_x;
    int y = m_y;
    if (x + 1 >= width) {
        x = 0;
        ++y;
    } else {
        ++x;
    }
    return Coordinate(x, y);
}
